<div class="datatable">
  <rd-widget>
    <rd-widget-body classes="no-padding">

      <div class="toolBar">
        <div class="toolBarTitle">
          <i class="fa" ng-class="$ctrl.titleIcon" aria-hidden="true" style="margin-right: 2px;"></i> {{ $ctrl.titleText }}
        </div>
      </div>

      <div class="actionBar">
        <div>
          <button type="button" class="btn btn-sm btn-primary" ui-sref="portainer.templates.new" ng-if="$ctrl.showAddAction">
            <i class="fa fa-plus space-right" aria-hidden="true"></i>Add template
          </button>
          <span ng-class="{ 'pull-right': $ctrl.showAddAction }" style="width: 25%;">
            <ui-select ng-model="$ctrl.state.selectedCategory">
              <ui-select-match placeholder="Select a category" allow-clear="true">
                <span>{{ $select.selected }}</span>
              </ui-select-match>
              <ui-select-choices repeat="category in ($ctrl.state.categories | filter: $select.search)">
                <span>{{ category }}</span>
              </ui-select-choices>
            </ui-select>
          </span>
        </div>

        <div class="small text-muted" style="margin: 15px 0 0 5px;">
          <label for="show_stacks" class="control-label text-left">
            Show container templates
          </label>
          <label class="switch" style="margin-left: 20px;">
            <input type="checkbox" name="show_stacks" ng-model="$ctrl.state.showContainerTemplates" ng-change="$ctrl.updateCategories()"><i></i>
          </label>
        </div>
      </div>

      <div class="searchBar" style="border-top: 2px solid #f6f6f6;">
        <i class="fa fa-search searchIcon" aria-hidden="true"></i>
        <input type="text" class="searchInput" ng-model="$ctrl.state.textFilter" ng-change="$ctrl.onTextFilterChange()" placeholder="Search..." auto-focus ng-model-options="{ debounce: 300 }">
      </div>

      <div class="blocklist">
        <template-item
          ng-repeat="template in $ctrl.templates | filter: $ctrl.filterByType | filter:$ctrl.filterByCategory | filter:$ctrl.state.textFilter"
          model="template"
          show-update-action="$ctrl.showUpdateAction"
          show-delete-action="$ctrl.showDeleteAction"
          on-select="$ctrl.selectAction"
          on-delete="$ctrl.deleteAction"
        ></template-item>
        <div ng-if="!$ctrl.templates" class="text-center text-muted">
          Loading...
        </div>
        <div ng-if="($ctrl.templates | filter: $ctrl.filterByType | filter:$ctrl.filterByCategory | filter:$ctrl.state.textFilter).length === 0" class="text-center text-muted">
          No templates available.
        </div>
      </div>

    </rd-widget-body>
  </rd-widget>
</div>
